package com.higgins.law.server;

import java.io.InputStream;
import java.util.ArrayList;

import com.google.api.services.drive.Drive;
import com.google.api.services.drive.model.File;
import com.google.gdata.client.spreadsheet.SpreadsheetService;
import com.google.gdata.data.spreadsheet.SpreadsheetEntry;

public class WordDocumentFactory {
	private WordDocumentGoogleDrive myGoogleDrive;
	private Drive drive ;
	
	public WordDocumentFactory() {
		try	{
			myGoogleDrive = new WordDocumentGoogleDrive();
			drive = myGoogleDrive.authenticate();
		} catch (Exception e)	{
			System.out.println("Something has gone wrong!");
		}
	}
	
	public void createCoveringLetter(String originalFileTitle, String originalFileGoogleId, String lawFirm, String address, String contact)	{
		  try {
				String duplicateFileTitle = myGoogleDrive.generateDuplicateFileName(originalFileTitle, lawFirm);
				
				File myDuplicateFile = GoogleDrive.copyFile(drive, originalFileGoogleId, duplicateFileTitle);

				InputStream inputStream = GoogleDrive.downloadWordFile(drive, myDuplicateFile);

				MSWordService myService = new MSWordService();
				java.io.File finalFile = myService.updateMSWordFile(inputStream, lawFirm, address, contact);
				
				GoogleDrive.updateFile(drive, myDuplicateFile, finalFile);
				
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
	}
}
